<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;

class User extends Authenticatable {

	use HasApiTokens, Notifiable;

	/**
	 * The attributes that are mass assignable.
	 *
	 * @var array
	 */
	protected $fillable = [
		'name', 'teacher_id', 'admin_id', 'name_en', 'age', 'work', 'phone', 'password', 'headimg', 'lesson_all_num', 'lesson_ea_num', 'lesson_left_num', 'lesson_ph_num', 'leave_num', 'task_num', 'score_num', 'hour_num', 'created_at', 'updated_at',
	];

	/**
	 * The attributes that should be hidden for arrays.
	 *
	 * @var array
	 */
	protected $hidden = [
		// 'password', 'remember_token',
	];

	/**
	 * 自定义用Passport授权登录查询的usename字段
	 * @param $username
	 * @return mixed
	 */
	public function findForPassport($username) {
		return self::where('phone', $username)->first();
	}

	public function adminUsers() {
		return $this->belongsTo('App\Models\AdminUsers', 'admin_id');
	}

	public function teachers() {
		return $this->belongsTo('App\Models\STeacherInfo', 'teacher_id');
	}
}
